<?php 
/**
 * **控制器
 */
class OrdCenController extends Controller{
    /**
     * 
     */
    public function index(){
    	//如果已经登录
    	if(isset($_SESSION['uid'])){
	       	$uid = $_SESSION['uid'];
			
			//默认不点击订单列表
			$w = isset($_GET['w']) ? $_GET['w'] : 0;
			if($w==0){
				$Gdata = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid JOIN __order_list__ ol ON o.oid=ol.order_oid JOIN __goods__ g ON ol.goods_gid=g.gid')->where("uid={$uid}")->all();
				$order = array();
				foreach ($Gdata as $k => $v) {
					$order[$v['oid']]['time']=$v['time'];
					$order[$v['oid']]['number']=$v['number'];
					$order[$v['oid']]['list'][]=$v;
				}
			}
			//如果点击待付款
			if($w==1){
				$Gdata = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid JOIN __order_list__ ol ON o.oid=ol.order_oid JOIN __goods__ g ON ol.goods_gid=g.gid')->where("uid={$uid} AND status='待付款'")->all();
				$order = array();
				foreach ($Gdata as $k => $v) {
					$order[$v['oid']]['time']=$v['time'];
					$order[$v['oid']]['number']=$v['number'];
					$order[$v['oid']]['list'][]=$v;
				}
			}
			//如果点击运送中
			if($w==2){
				$Gdata = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid JOIN __order_list__ ol ON o.oid=ol.order_oid JOIN __goods__ g ON ol.goods_gid=g.gid')->where("uid={$uid} AND status IN('已付款','已发货')")->all();
				$order = array();
				foreach ($Gdata as $k => $v) {
					$order[$v['oid']]['time']=$v['time'];
					$order[$v['oid']]['number']=$v['number'];
					$order[$v['oid']]['list'][]=$v;
				}
			}
			
			//*******************统计信息************************
			//共多少订单
			$All = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid JOIN __order_list__ ol ON o.oid=ol.order_oid JOIN __goods__ g ON ol.goods_gid=g.gid')->where("uid={$uid}")->all();
			$or = array();
			foreach ($All as $k => $v) {
				$or[$v['oid']]['list'][]=$v;
			}
			$allOrder = count($or);
			//待付款
			$loadOrder = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid')->where("uid={$uid} AND status='待付款'")->count();
			//运送中
			$goOrder1 = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid')->where("uid={$uid} AND status='已付款'")->count();
			$goOrder2 = M()->join('__user__ u JOIN __jp_order__ o ON u.uid=o.user_uid')->where("uid={$uid} AND status='已发货'")->count();
			//订单统计信息
			$count['allOrder'] = $allOrder;
			$count['loadOrder'] = $loadOrder;
			$count['goOrder'] = $goOrder1+$goOrder2;
			
			//分配数据
			$this->assign('count',$count);
			
			$this->assign('order',$order);
			$this->display();
		}else{
			$this->error('您还未登陆，请登录……',U('Login/index'));
		}
    }
	
	/**
	 * 取消订单
	 */
	public function delOrder(){
	    $oid = Q('get.oid',0,'intval');
		//删除订单表数据
		K('Order')->where("oid={$oid}")->delete();
		//删除订单列表数据
		K('OrderList')->where("order_oid={$oid}")->delete();
		$this->success('取消订单成功');
	}
	
	/**
	 * 确认收货
	 */
	public function Sure(){
	    $oid = Q('get.oid',0,'intval');
		K('Order')->where("oid={$oid}")->update(array('status'=>'已收货'));
		$this->success('交易完成，感谢您对卷皮的青睐……', U('OrdCen/index'));
	}
	
	
	
	
	
	
	
	
 }

 ?>